package cn.xuqiudong.rpc.protocol.netty.model;

import java.io.Serializable;

/**
 * 描述: netty 通信数据格式的头部分
 *    <p>
 *        1. 2byte 魔法数
 *        2. 序列化方式
 *        3. 1byte 请求类型
 *        4. 8byte 请求标识
 *        5. 4byte 数据长度
 *        请求头总长度为：16 byte
 *    </p>
 * @author Vic.xu
 * @date 2022-02-21 10:38
 */
public class NettyHeader implements Serializable {

    private static final long serialVersionUID = -8359579326591367067L;

    /**
     * 魔数-用来验证报文的身份（2个字节）
     */
    private short magic;

    /**
     * 预留的序列化方式
     */
    private byte serialType;
    /**
     * 操作类型（1个字节）
     */
    private byte requestType;
    /**
     * 请求id（8个字节）
     */
    private long requestId;
    /**
     * 数据长度（4个字节）
     */
    private int length;

    public NettyHeader() {
    }

    public NettyHeader(short magic, byte requestType, long requestId) {
        this.magic = magic;
        this.requestType = requestType;
        this.requestId = requestId;
    }

    public NettyHeader(short magic, byte requestType, long requestId, int length) {
        this.magic = magic;
        this.requestType = requestType;
        this.requestId = requestId;
        this.length = length;
    }

    public short getMagic() {
        return magic;
    }

    public void setMagic(short magic) {
        this.magic = magic;
    }

    public byte getRequestType() {
        return requestType;
    }

    public void setRequestType(byte requestType) {
        this.requestType = requestType;
    }

    public long getRequestId() {
        return requestId;
    }

    public void setRequestId(long requestId) {
        this.requestId = requestId;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public byte getSerialType() {
        return serialType;
    }

    public void setSerialType(byte serialType) {
        this.serialType = serialType;
    }
}
